/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs;

import org.rails.extjs.javascript.JavaScript;

public class Resizable extends Observable {

	protected String elId;
	
	public Resizable(String elId) {
		super();
		this.elId = elId;
	}
	
	public void setAdjustments(Integer width,Integer height){
		addOption("adjustments",new JavaScript("["+width+","+height+"]"));
	}
	
	public void setAnimate(Boolean animate){
		addOption("animate",animate);
	}
	
	public Boolean isAnimate(){
		return getBoolean("animate",false);
	}
	
	public void setConstrainTo(String constrainTo){
		addOption("constrainTo",constrainTo);
	}

	public String getConstrainTo(){
		return getString("constrainTo","");
	}
	
	public void setDisableTrackOver(Boolean disableTrackOver){
		addOption("disableTrackOver",disableTrackOver);
	}
	
	public Boolean isDisableTrackOver(){
		return getBoolean("disableTrackOver",false);
	}
	
	public void setDraggable(Boolean draggable){
		addOption("draggable",draggable);
	}
	
	public Boolean isDraggable(){
		return getBoolean("draggable",false);
	}
	
	public void setDuration(Number duration){
		addOption("duration",duration);
	}
	
	public Number getDuration(){
		return getNumber("duration",0.35);
	}
	
	public void setDynamic(Boolean dynamic){
		addOption("dynamic",dynamic);
	}
	
	public Boolean isDynamic(){
		return getBoolean("dynamic",false);
	}
	
	public void setEasing(String easing){
		addOption("easing",easing);
	}
	
	public String getEasing(){
		return getString("easing","easingOutStrong");
	}
	
	public void setEnabled(Boolean enabled){
		addOption("enabled",enabled);
	}
	
	public Boolean isEnabled(){		
		return getBoolean("enabled",true);
	}
	
	public void setHandleCls(String handleCls){
		addOption("handleCls",handleCls);
	}
	
	public String getHandleCls(){
		return getString("handleCls","");
	}
	
	public void setHandles(String handles){
		addOption("handles", handles);
	}
	
	public String getHandles(){
		return getString("handles", "");
	}
	
	public void setHeight(Integer height){
		addOption("height", height);
	}
	
	public Integer getHeight(){
		return getInteger("height",0);
	}
	
	public void setHeightIncrement(Integer heightIncrement){
		addOption("heightIncrement", heightIncrement);
	}
	
	public Integer getHeightIncrement(){
		return getInteger("heightIncrement", 0);
	}
	
	public void setMaxHeight(Integer maxHeight){
		addOption("maxHeight", maxHeight);
	}
	
	public Integer getMaxHeight(){
		return getInteger("maxHeight", 10000);
	}
	
	public void setMinHeight(Integer minHeight){
		addOption("minHeight", minHeight);
	}
	
	public Integer getMinHeight(){
		return getInteger("minHeight", 5);
	}
	
	public void setMaxWindth(Integer maxWidth){
		addOption("maxWidth", maxWidth);
	}
	
	public Integer getMaxWindth(){
		return getInteger("maxWidth", 10000);
	}
	
	public void setMinWidth(Integer minWidth){
		addOption("minWidth", minWidth);
	}
	
	public Integer getMinWidth(){
		return getInteger("minWidth", 5);
	}
	
	public void setMinX(Integer minX){
		addOption("minX", minX);
	}
	
	public Integer getMinX(){
		return getInteger("minX", 0);
	}
	
	public void setMinY(Integer minY){
		addOption("minY", minY);
	}
	
	public Integer getMinY(){
		return getInteger("minY", 0);
	}
	
	public void setMultiDirectional(Boolean multiDirectional){
		addOption("multiDirectional", multiDirectional);
	}
	
	public Boolean isMultiDirectional(){
		return getBoolean("multiDirectional", false);
	}
	
	public void setPinned(Boolean pinned){
		addOption("pinned",pinned);
	}
	
	public Boolean isPinned(){
		return getBoolean("pinned",false);
	}
	
	public void setPreserveRatio(Boolean preserveRatio){
		addOption("preserveRatio", preserveRatio);
	}
	
	public Boolean isPreserveRatio(){
		return getBoolean("preserveRatio", false);
	}
	
	public void setResizeChild(Boolean resizeChild){
		addOption("resizeChild", resizeChild);
	}
	
	public Boolean isResizeChild(){
		return getBoolean("resizeChild", false);
	}
	
	public void setResizeRegion(Object resizeRegion){
		addOption("resizeRegion", resizeRegion);
	}
	
	public Object getResizeRegion(){
		return getOption("resizeRegion");
	}
	
	public void setTransparent(Boolean transparent){
		addOption("transparent", transparent);
	}
	
	public Boolean isTransparent(){
		return getBoolean("transparent", false);
	}
	
	public void setWidth(Integer width){
		addOption("width", width);
	}
	
	public Integer getWidth(){
		return getInteger("width", 0);
	}
	
	public void setWidthIncrement(Integer widthIncrement){
		addOption("widthIncrement", widthIncrement);
	}
	
	public Integer getWidthIncrement(){
		return getInteger("widthIncrement", 0);
	}
	
	public void setWrap(Boolean wrap){
		addOption("wrap", wrap);
	}
	
	public Boolean isWrap(){
		return getBoolean("wrap", false);
	}
	
	@Override
	public String getScript() {
		script = new StringBuffer("");
		createItems();
		script.append("new new Ext.Resizable('" + elId + "',");
		script.append(createOptions());
		script.append(")");
		return script.toString();
	}

}
